package com.yingside.game;

import java.util.ArrayList;
import java.util.List;

public class Store {
    private List<Weapon> weaponList;

    public Store(){
        weaponList = new ArrayList<>();
        Weapon w1 = new Weapon("多兰之剑",40,400,10);
        Weapon w2 = new Weapon("暴风大剑",70,1300,5);
        Weapon w3 = new Weapon("倚天之剑",100,2400,2);
        Weapon w4 = new Weapon("霜之哀伤",140,4400,1);
        Weapon w5 = new Weapon("灰烬使者",200,10000,1);
        weaponList.add(w1);
        weaponList.add(w2);
        weaponList.add(w3);
        weaponList.add(w4);
        weaponList.add(w5);
    }

    public List<Weapon> getWeaponList() {
        return weaponList;
    }

    public void setWeaponList(List<Weapon> weaponList) {
        this.weaponList = weaponList;
    }

    /**
     * 给英雄卖武器
     * @param weapon
     * @param h
     */
    public boolean sell(Weapon weapon, Hero h) {
        boolean flag = false;
        //首先判断
        if (h.getOwnMoney() < weapon.getPrice()) {
            System.err.println("英雄你的金钱不够哦...请先去打怪赚钱吧~~~");
        }
        else if(weapon.getNum() <= 0){
            System.err.println("对不起，该武器库存不够，请稍后再进行购买");
        }
        else{
            //扣钱
            h.setOwnMoney(h.getOwnMoney() - weapon.getPrice());
            //武器库存-1
            weapon.setNum(weapon.getNum() - 1);
            //英雄的武器背包放入新的武器
            h.getWeaponBag().add(weapon);
            flag = true;
        }
        return flag;
    }
}
